package com.huawei.statistics.service.impl.video;

import com.huawei.statistics.pojo.video.TVPlay;
import com.huawei.statistics.service.impl.common.BaseServiceImpl;
import com.huawei.statistics.service.video.TVPlayService;
import com.huawei.statistics.vo.common.HttpResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 18573 on 2019/1/18.
 */
@Service
public class TVPlayServiceImpl extends BaseServiceImpl implements TVPlayService {


    @Override
    public TVPlay getTVPlayById(Long id) {

        return getEntityById(id,TVPlay.class);
    }

    @Override
    public HttpResult addTVPlay(TVPlay tvplay) {

        return new HttpResult(HttpResult.OK,addEntity(tvplay));
    }

    @Override
    public HttpResult updateTVPlay(TVPlay tvPlay) {

        return new HttpResult(HttpResult.OK,updateEntityValues(tvPlay));
    }

    @Override
    public List<TVPlay> getTVPlayByVid(Long vid) {
        Map<String,Object> map = new HashMap<>();
        map.put("videoId",vid);
        return getEntityByMap(TVPlay.class,map);
    }


    @Override
    public HttpResult deleteTVPlayByVid(Long vid) {
        Map<String,Object> map = new HashMap<>();
        int count = getEntityCountByPropertyName(TVPlay.class,"videoId",vid);
        Boolean b = false;
        if(count > 0){
            b = deleteByOneProperty(TVPlay.class,"videoId",vid);
        }
        return new HttpResult(HttpResult.OK,b);
    }


    @Override
    public HttpResult addTVPlayByList(List<TVPlay> list) {
        try{
            if(list != null && list.size() > 0 ){
                for(TVPlay play:list){
                    Boolean b = addEntity(play);
                }
            }
        }catch (Exception e){
            throw new RuntimeException(list.get(0).getTitle()+"保存时出错！");
        }
        return new HttpResult(HttpResult.OK,true);
    }
}
